package com.ruoyi.forum.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.forum.domain.ForumSpecialty;
import com.ruoyi.forum.service.IForumSpecialtyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 专业管理Controller
 * 
 * @author ruoyi
 * @date 2024-02-01
 */
@RestController
@RequestMapping("/forum/specialty")
public class ForumSpecialtyController extends BaseController
{
    @Autowired
    private IForumSpecialtyService forumSpecialtyService;

    /**
     * 查询专业管理列表
     */
//    @PreAuthorize("@ss.hasPermi('forum:specialty:list')")
    @GetMapping("/list")
    @Anonymous
    public TableDataInfo list(ForumSpecialty forumSpecialty)
    {
        startPage();
        if(forumSpecialty.getDelFlag()==null){
            forumSpecialty.setDelFlag("0");
        }
        List<ForumSpecialty> list = forumSpecialtyService.selectForumSpecialtyList(forumSpecialty);
        return getDataTable(list);
    }

    /**
     *前台系统-获取所有的专业
     */
//    @PreAuthorize("@ss.hasPermi('forum:specialty:list')")
    @GetMapping("/briefList")
    @Anonymous
    public TableDataInfo listForQian(ForumSpecialty forumSpecialty)
    {
        if(forumSpecialty.getDelFlag()==null){
            forumSpecialty.setDelFlag("0");
        }
        List<ForumSpecialty> list = forumSpecialtyService.selectForumSpecialtyList(forumSpecialty);
        return getDataTable(list);
    }

    /**
     * 导出专业管理列表
     */
    @PreAuthorize("@ss.hasPermi('forum:specialty:export')")
    @Log(title = "专业管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ForumSpecialty forumSpecialty)
    {
        List<ForumSpecialty> list = forumSpecialtyService.selectForumSpecialtyList(forumSpecialty);
        ExcelUtil<ForumSpecialty> util = new ExcelUtil<ForumSpecialty>(ForumSpecialty.class);
        util.exportExcel(response, list, "专业管理数据");
    }

    /**
     * 获取专业管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('forum:specialty:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(forumSpecialtyService.selectForumSpecialtyById(id));
    }

    /**
     * 新增专业管理
     */
    @PreAuthorize("@ss.hasPermi('forum:specialty:add')")
    @Log(title = "专业管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ForumSpecialty forumSpecialty)
    {
        forumSpecialty.setCreateBy(getUsername());
        return toAjax(forumSpecialtyService.insertForumSpecialty(forumSpecialty));
    }

    /**
     * 修改专业管理
     */
    @PreAuthorize("@ss.hasPermi('forum:specialty:edit')")
    @Log(title = "专业管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ForumSpecialty forumSpecialty)
    {
        forumSpecialty.setUpdateBy(getUsername());
        return toAjax(forumSpecialtyService.updateForumSpecialty(forumSpecialty));
    }

    /**
     * 删除专业管理
     */
    @PreAuthorize("@ss.hasPermi('forum:specialty:remove')")
    @Log(title = "专业管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(forumSpecialtyService.deleteForumSpecialtyByIds(ids));
    }
}
